<template>
  <div>
    <!-- 顶部统计 -->
    <analyze :checkInData="checkInData"></analyze>
    <el-form :model="queryParams" ref="queryForm" size="mini" v-show="showSearch" label-width="68px">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="项目区域" prop="projectRegion">
            <el-select v-model="queryParams.projectRegion" placeholder="请选择" clearable
              @keyup.enter.native="handleQuery">
              <el-option v-for="dict in dict.type.cld_project_region" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="服务日期" prop="serviceDate">
            <el-date-picker type="month" clearable v-model="queryParams.serviceDate" value-format="yyyy-MM-dd"
              placeholder="请选择服务日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="settlementList" border>
      <el-table-column label="项目区域" align="center" prop="projectRegion">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_region" :value="scope.row.projectRegion" />
        </template>
      </el-table-column>
      <el-table-column label="应收款金额" align="center" prop="amountDue">
        <template slot-scope="scope">
          {{ toMoney(scope.row.amountDue) }}
        </template>
      </el-table-column>
      <el-table-column label="开票金额" align="center" prop="actualAmount">
        <template slot-scope="scope">
          {{ toMoney(scope.row.actualAmount) }}
        </template>
      </el-table-column>
      <el-table-column label="实收款金额" align="center">
        <template slot-scope="scope">
          {{ toMoney(scope.row.receivedMoney) }}
        </template>
      </el-table-column>
      <el-table-column label="未收款金额" align="center">
        <template slot-scope="scope">
          {{ toMoney(scope.row.amountDue - scope.row.receivedMoney) }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="差额" align="center">
        <template slot-scope="scope">
          {{ toMoney(scope.row.amountDue - (scope.row.actualAmount - scope.row.baddebtMoney)) }}
        </template>
      </el-table-column> -->
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import moment from 'moment';
import { groupByRegionList } from "@/api/cld/settlement";
import analyze from "./analyze.vue";
export default {
  name: "region",
  dicts: ['cld_project_region'],
  components: {
    analyze
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 结算管理表格数据
      settlementList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectRegion: null,
        serviceDate: this.parseTime(moment().clone().subtract(1, 'months').format(), '{y}-{m}')
      },
      checkInData: this.parseTime(moment().clone().subtract(1, 'months').format(), '{y}-{m}')
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询发票管理列表 */
    getList() {
      this.loading = true;
      groupByRegionList(this.queryParams).then(response => {
        this.settlementList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.checkInData = this.queryParams.serviceDate;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
<style scoped>
.el-select {
  width: 100%;
}

.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
</style>
